package com.chuji.crmcj.fragment;

import java.util.HashMap;

public class FragmentFactory {

    private static BaseFragment fragment;

    private static final int TAB_SALE_HOME = 0;
    private static final int TAB_TASK = 1;
    private static final int TAB_SET = 2;
    private static final int TAB_MAG_HOME = 3;
    private static final int TAB_MAG_MANAGER = 4;

    private static HashMap<Integer, BaseFragment> mHashMapFragments = new HashMap<Integer, BaseFragment>();

    public static BaseFragment createFragment(int position) {
        // 从内存缓存当中获取到fragment
        fragment = mHashMapFragments.get(position);

        if (fragment == null) {
            switch (position) {
                case TAB_SALE_HOME:
                    fragment = new SaleHomeFragment();
                    break;
                case TAB_TASK:
                    fragment = new TaskFragment();
                    break;
                case TAB_MAG_HOME:
                    fragment = new MagHomeFragment();
                    break;
                case TAB_MAG_MANAGER:
                    fragment = new MagManFragment();
                    break;
            }
            //缓存fragment
            mHashMapFragments.put(position, fragment);
        }
        return fragment;
    }
}
